package com.tfy.liquor.dao;

import com.tfy.liquor.bean.UserShoppingAddress;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Mapper
@Service
public interface UserShoppingAddressDao {
    // 添加收货地址信息
    @Insert("insert into user_shopping_address values(null, ${userId}, '${mobile}', '${userName}', ${province}, '${provinceName}', ${city}, '${cityName}', ${area}, '${areaName}', ${town}, '${townName}', '${detail}', '${areaCode}', '${postalCode}', ${isDefault}, '${createTime}', '${updateTime}', 0)")
    int addUserShoppingAddress(UserShoppingAddress userShoppingAddress);

    // 根据用户信息获取收货地址
    @Select("select * from user_shopping_address where userId=${userId} and delFlag=0 order by id desc")
    ArrayList<UserShoppingAddress> getUserShoppingAddressByUserId(Long userId);

    // 根据收货地址编号获取信息
    @Select("select * from user_shopping_address where id=${id}")
    UserShoppingAddress getUserShoppingAddressById(int addressId);

    // 停用收货地址信息
    @Update("update user_shopping_address set delFlag=1, updateTime='${updateTime}' where id=${id}")
    int stopUserShoppingAddressById(UserShoppingAddress userShoppingAddress);

    // 取消用户所有默认地址
    @Update("update user_shopping_address set isDefault=0, updateTime='${updateTime}' where userId=${userId}")
    int stopUserShoppingIsDefault(UserShoppingAddress userShoppingAddress);

    // 获取默认收货地址
    @Select("select * from user_shopping_address where userId=${userId} and isDefault=1")
    UserShoppingAddress getDefaultUserShoppingAddress(Long userId);

    // 根据地址编号获取地址信息
    @Select("select * from user_shopping_address where id=${id}")
    UserShoppingAddress getUserShoppingById(Long id);
}
